//
//  HYZXCell.m
//  HYHoney
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HYZXCell.h"
#import "ModelForZX.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"

@implementation HYZXCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createCell];
    }
    return self;
}


- (void)dealloc{
    
    [_imageV release];
    [_labelOfTitle release];
    [_labelOfname release];
    [_labelOfTime release];
    [_width release];
    [_height release];
    [_viewLine release];
    [super dealloc];
}


- (void)createCell{
    
    self.imageV = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageV];
    
    self.labelOfTitle = [[UILabel alloc] init];
    self.labelOfTitle.backgroundColor = [UIColor clearColor];
    self.labelOfTitle.font = [UIFont boldSystemFontOfSize:15];
    self.labelOfTitle.numberOfLines = 0;
    [self.contentView addSubview:self.labelOfTitle];
    
    self.labelOfname = [[UILabel alloc] init];
//    self.labelOfname.backgroundColor = [UIColor yellowColor];
    self.labelOfname.font = [UIFont boldSystemFontOfSize:16];
    [self.contentView addSubview:self.labelOfname];
    
    self.labelOfTime = [[UILabel alloc] init];
//    self.labelOfTime.backgroundColor = [UIColor cyanColor];
    self.labelOfTime.font = [UIFont boldSystemFontOfSize:14];
    [self.contentView addSubview:self.labelOfTime];
    
    self.width = [[NSString alloc] init];
    self.height = [[NSString alloc] init];
    
    
    [self.imageV release];
    [self.labelOfTitle release];
    [self.labelOfname release];
    [self.labelOfTime release];
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.labelOfname.frame = CGRectMake(10, 20, self.frame.size.width / 3 * 2, 20);
    
    self.labelOfTime.frame = CGRectMake(self.frame.size.width / 2, 20, self.frame.size.width / 2 - 10, 20);
    
    self.viewLine = [[UIView alloc] init];
    self.viewLine.frame = CGRectMake(7, 20 + 20 + 5, self.frame.size.width - 14, 2);
    self.viewLine.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.viewLine];
    self.viewLine.dk_backgroundColorPicker = DKColorWithRGB(0xff0000, 0xff6a6a);
    self.labelOfTitle.frame = CGRectMake(10, 20 + 20 + 10 + 3, self.frame.size.width - 10, [[self class] heightForLabel:self.labelOfTitle.text]);
    
    self.imageV.frame = CGRectMake((self.contentView.frame.size.width - 200) / 2, 20 + 20 + 10 + 10 + [[self class] heightForLabel:self.labelOfTitle.text], 200, [self.height floatValue] / [self.width floatValue] * 200);
    
//    self.imageV.layer.masksToBounds = YES;
    
}


+ (CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 20, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil];
    
    return rect.size.height;
}


+ (CGFloat)heightForCellZX:(ModelForZX *)modelZX{

    CGFloat height = [HYZXCell heightForLabel:modelZX.title];
    CGFloat height2 = [modelZX.height floatValue] / [modelZX.width floatValue] * 200;
    
    return height + height2 + 20 + 20 + 20 + 10;
}

- (void)passmodel:(ModelForZX *)modelZX{

    [self.imageV sd_setImageWithURL:[NSURL URLWithString:modelZX.thumbnail] placeholderImage:[UIImage imageNamed:@"jzz"]];
    
    
    
    self.labelOfTitle.text = modelZX.title;
    self.labelOfTitle.dk_textColorPicker = DKColorWithRGB(0x000000, 0xc6e2ef);
    
    self.labelOfTime.text = modelZX.created_at;
    self.labelOfTime.dk_textColorPicker = DKColorWithRGB(0x000000, 0xefffff);
    
    self.labelOfname.text = modelZX.screen_name;
    self.labelOfname.dk_textColorPicker = DKColorWithRGB(0x000000, 0xe0ffff);
    
    self.width = modelZX.width;
    self.height = modelZX.height;
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
